home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / astronut < prev    next >
Text File  |  1995-03-31  |  9KB  |  304 lines

  1. %%HP: T(3)A(R)F(.); 
  2. @ AstroNUT V1.0 
  3. @ by Kevin Jessup 
  4. @ 12-May-1991 
  5. @ Introduction 
  6. @ ------------ 
  7. @ AstroNUT is a lunar lander simulation for the 48SX. 
  8. @ It supports 2-d travel (up, down, left, right) and a 
  9. @ random terraine that is generated for each new game. 
  10. @ All routines are in RPL so the screen updates are somewhat 
  11. @ slow.  I still find play acceptable however. 
  12. @ The object of the game is to land on a more or less flat 
  13. @ portion of the lunar surface with a horizontal velocity of 
  14. @ zero and a vertical velocity of less than 5 feet per second. 
  15. @ (Somewhat fast! Change it if you like.)  You have a limited 
  16. @ amount of fuel available to do this. 
  17. @ Initial parameters 
  18. @ ------------------ 
  19. @ Altitude:            170 feet 
  20. @ Vertical velocity:   -20 feet per second.  A "second" is 
  21. @                      not the usual unit of time that you 
  22. @                      are familiar with but how long it takes 
  23. @                      this game to execute it's main loop! 
  24. @                      You will have to hit the thrust key 
  25. @                      quite often to slow down.  Read on... 
  26. @ Horizontal velocity: 5 feet per second.  The direction 
  27. @                      (left or right) is random.  The initial 
  28. @                      horizontal position is also random. 
  29. @ Fuel:                100 units.  In gallons, liters, cubic 
  30. @                      light-years or whatever you'd like to 
  31. @                      call it :-) 
  32. @ Control keys 
  33. @ ------------ 
  34. @ 8: Apply upward thrust (One push equals thrust of 1/2 g) 
  35. @ 4: Apply left thrust (Changes horizontal vel. by 1 ft/sec) 
  36. @ 6: Apply right thrust (Changes horizontal vel. by 1 ft/sec) 
  37. @ With each screen update, your downward velocity will 
  38. @ increase due to the acceleration of gravity at a rate of 
  39. @ 4 ft/s^2.  It will require 2 hits of the vertical thrust 
  40. @ (key 8) to exactly compensate for the acceleration due to 
  41. @ gravity. 
  42. @ Screen positioning 
  43. @ ------------------ 
  44. @ As you move to the left and right edges of the display, you 
  45. @ will wrap around to the opposite side.  There are "unlimited" 
  46. @ vertical screens.  You will wrap around at the top and bottom. 
  47. @ When you reach the lowest screen, there will be a slight pause 
  48. @ as the lunar surface is drawn.  If you move above the lowest 
  49. @ screen, the surface will be erased.  The current "flight 
  50. @ parameters" are displayed at the top right of the LCD. 
  51. @ Loading 
  52. @ ------- 
  53. @ For the neophytes, those funny litle characters at the start 
  54. @ of these lines are HP48SX comment delimiters.  You can transfer 
  55. @ this entire file AS IS to your 48.  The 48 will remove all the 
  56. @ comments and load only the code. 
  57. @ After transferring this file to your 48, recall the directory 
  58. @ to the stack.  Execute the BYTES command.  You should get the 
  59. @ following... 
  60. @              Level 2:    # 7F4h 
  61. @              Level 1:    2368.5 
  62. @ These numbers are only valid if you have not yet run the game. 
  63. @ The game will create additional variables and leave them in 
  64. @ the directory upon completion.  Once you have successfully 
  65. @ transferred the directory to your 48, just hit PLAY to start. 
  66. @ Upon completion, hit ON to clear the display.  After running it 
  67. @ the firt time, you may want to reorder your directory so that 
  68. @ PLAY is the first variable.   
  69. @ Be patient...after a little practice, you should be able to 
  70. @ land using only 100 units of fuel.  You can modify the amount 
  71. @ of fuel, thrust and acceleration due to gravity if you like. 
  72. @ Study the code below to find out how.  Have fun! 
  73. @ This is "freeware" but if you'd like to send a few bucks, don't 
  74. @ let that stop you! 
  75. @ Kevin Jessup 
  76. @ 9118 N 85th 
  77. @ Milwaukee, WI 53224 
  78. @ (414)355-9752 
  79. @ Milwaukee HP48SX BBS 
  80. @ 2400/1200/300 baud 
  81. @ (414)362-2020 
  82. @ 6PM to 7AM or all day Sunday 
  83.  
  84. DIR                   @ AstroNUT directory 
  85.  
  86.   PLAY                @ push PLAY to start 
  87.     \<< RCLF 3 FIX    @ save flags 
  88. # 83h # 40h BLANK     @ create a blank PICT 
  89. PICT STO 1 CF         @ clear the crash flag 
  90. 170 'ht' STO          @ set height to 170 feet 
  91. -20 'v' STO 5         @ set vertical v to -20 
  92.       IF RAND .5 <    @ set horiz v to 5 or -5 
  93.       THEN NEG 
  94.       END 'hv' STO 
  95. RAND 80 * IP 'x'      @ random horiz position 
  96. STO 100 'fuel' STO    @ 100 unit of fuel 
  97. 2 CF                  @ clear the bottom flag 
  98. MAKBOTTOM { # 0h      @ random terrain coordinates 
  99. # 0h } PVIEW MAIN     @ display and loop on main 
  100. CRASHht 'ht' STO      @ display landing parameters 
  101. CRASHx 'x' STO 
  102. CRASHv 'v' STO 
  103. STATUS PICT NEWC      @ display landing position 
  104. SHIP GXOR PICT {      @ display AstroNUT or CRASH 
  105. # 5h # 5h } 
  106.       IF CRASHv -4    @ test slope, vv and hv 
  107. < CRASHsl ABS .084 
  108. > OR hv OR 
  109.       THEN 
  110. "*CRASH*" 
  111.       ELSE PICT 7 
  112. 'ht' STO+ 1 'x' 
  113. STO+ NEWC aflag REPL 
  114. "AstroNUT" 
  115.       END 3 \->GROB 
  116. REPL 7 FREEZE         @ freeze the display 
  117.       WHILE KEY       @ flush any excess keys 
  118.       REPEAT DROP 
  119.       END STOF        @ restore flags and quit 
  120.     \>> 
  121.  
  122.   MAIN                @ main processing loop 
  123.     \<< 
  124.       DO              @ draw or erase the terraine 
  125.         IF ht 56 > 
  126.         THEN 
  127.           IF 2 FS? 
  128.           THEN 
  129. ERASE 2 CF 
  130.           END 
  131.         ELSE 
  132.           IF 2 FC? 
  133.           THEN 
  134. DRAWBOTTOM 2 SF 
  135.           END 
  136.         END STATUS    @ display flight parameters 
  137. NEWC PICT OVER SHIP   @ display the lander 
  138. GXOR v 'ht' STO+ hv   @ calculate new position 
  139. 'x' STO+                
  140.         IF x 124 >    @ wrap horizontal 
  141. x 0 < OR 
  142.         THEN x 125 
  143. MOD ABS 'x' STO 
  144.         END 
  145. CHKBOTTOM GETKEY ag   @ see if we crashed, process keys 
  146. 'v' STO+ PICT SWAP    @ acceleration increases v 
  147. SHIP GXOR             @ erase old position 
  148.       UNTIL 1 FS?     @ quit if we landed or crashed 
  149.       END 
  150.     \>> 
  151.  
  152. @ CHKBOTTOM is the routine that eats all the CPU time. 
  153. @ If anyone knows how to speed it up, please do so. 
  154. @ It works by calculating linear regressions and then 
  155. @ comparing the line slopes. 
  156.  
  157.   CHKBOTTOM           @ set flag 1 if we crashed 
  158.     \<< 1 botCOORDS   @ get terraine coordinates list size 
  159. SIZE 1 - 
  160.       FOR i           @ test each line segment 
  161. botCOORDS i GETI 3    @ get line endpoints 
  162. ROLLD GET DUP2 1      @ duplicate them 
  163. GET SWAP 1 GET        @ get the x coordinates and 
  164.         IF x 3 + \<=  @ see if lander is between them 
  165. SWAP x 3 + > AND 
  166.         THEN OVER     @ if so, compare line slopes 
  167. C\->V2 CL\GS \GS+ C\->V2 \GS+ @ calculate line slope 
  168. LR x DUP 'CRASHx'     @ calculate and save possible 
  169. STO 3 + PREDY         @ crash x and y positions 
  170. 'CRASHht' STO SWAP 
  171. DROP DUP 'CRASHsl'    @ save crash slope 
  172. STO SWAP C\->V2 CL\GS @ calculate slope of line to 
  173. \GS+ x 3.001 + ht \->V2 @ the landers coordinates 
  174. \GS+ LR SWAP DROP 
  175.           IF \>=      @ if line segment slope >= the 
  176.           THEN 1 SF   @ slope of line to lander, 
  177.  v                    @ we crahed.  Set crash flag. 
  178. 'CRASHv' STO 99 'i'   @ save crash velocity 
  179. STO 
  180.           END 
  181.         ELSE DROP2    @ not within this line segment 
  182.         END 
  183.       NEXT            @ check next line 
  184.     \>> 
  185.  
  186.   MAKBOTTOM           @ generates a list of coordinates 
  187.     \<< { } 0 120     @ get an empty list 
  188.       FOR a a RAND    @ generate a random y coordinate 
  189. 25 * IP 6 + 2 \->LIST 
  190. 1 \->LIST + 12        @ save xy in list, do next 
  191.       STEP 130 OVER   @ line up the end points so 
  192. 1 GET OBJ\-> DROP     @ we don't impact on wrap 
  193. SWAP DROP 2 \->LIST 1 
  194. \->LIST + 9 RAND * IP @ insure at least one flat line 
  195. 2 + GETI 2 GET 3 
  196. ROLLD GETI 2 5 ROLL 
  197. PUT SWAP 1 - SWAP 
  198. PUT 'botCOORDS' STO   @ save the list 
  199.     \>> 
  200.  
  201.   DRAWBOTTOM          @ maps terraine coordinates to 
  202.     \<< 1 botCOORDS   @ screen and display the lines 
  203. SIZE 1 - 
  204.       FOR i 
  205. botCOORDS i GETI 
  206. OBJ\-> ROT R\->B ROT 63 
  207. SWAP - R\->B ROT 
  208. \->LIST 3 ROLLD GET 
  209. OBJ\-> ROT R\->B ROT 63 
  210. SWAP - R\->B ROT 
  211. \->LIST LINE 
  212.       NEXT 
  213.     \>> 
  214.  
  215.   STATUS              @ displays the flight parameters 
  216.     \<< 
  217.       \<< + 1 \->GROB 
  218. PICT 3 ROLLD REPL 
  219.       \>> \-> s 
  220.       \<< { # 54h 
  221. # 0h } "Height: " 
  222. ht s EVAL { # 54h 
  223. # 6h } "VertV:  " v 
  224. s EVAL { # 54h # Ch 
  225. } "HorizV: " hv s 
  226. EVAL { # 54h # 12h 
  227. } "Fuel:   " fuel s 
  228. EVAL 
  229.       \>> 
  230.     \>> 
  231.  
  232.   GETKEY              @ processes keys 
  233.     \<< 
  234.       WHILE KEY 
  235.       REPEAT 
  236.         IF fuel 0 >   @ but only if we got fuel! 
  237.         THEN 
  238.           CASE DUP 
  239. 72 == 
  240.             THEN -1 
  241. 'hv' STO+ -1 'fuel' 
  242. STO+ 
  243.             END DUP 
  244. 74 == 
  245.             THEN 1 
  246. 'hv' STO+ -1 'fuel' 
  247. STO+ 
  248.             END DUP 
  249. 63 == 
  250.             THEN 
  251. thrust DUP NEG 
  252. 'fuel' STO+ 'v' 
  253. STO+ 
  254.             END 
  255.           END 
  256.         END DROP 
  257.       END 
  258.     \>> 
  259.  
  260.   NEWC         @ get current screen coordiantes 
  261.     \<< x R\->B 57 1 ht 
  262. 57 MOD 57 / - * R\->B 
  263. 2 \->LIST 
  264.     \>> 
  265.  
  266.   C\->V2       @ convert 2-element list to vector 
  267.     \<< OBJ\-> DROP \->V2 
  268.     \>> 
  269.  
  270.   SHIP         @ GROB of the lander 
  271. GROB 6 6 E13333E11212 
  272.  
  273.   aflag        @ GROB of a flag 
  274. GROB 7 7 F7747414F71010 
  275.  
  276.   thrust 2     @ vertical thrust = -1/2 ag 
  277.  
  278.   ag -4        @ acceleration due to gravity 
  279.  
  280. END 
  281.  
  282. @ END OF ASCII FILE 
  283.